<?php
/**                                          
 * 第三方登录操作
 * @author M2
 * @version 1.0
 * create Date 2013-04-27
 */
class LoginModel extends Model {
	/**
	 * 获取登录绑定信息	
	 * @param
	 */
	public function loginBindInfo($uid=null) {
		if(session('?rm')) {
			$rm = session('rm');
			$logins['uid'] = isset($uid)?$uid:$_SESSION['mid'];
			$logins['openid'] = $rm['openid'];
			$logins['type'] = $rm['type'];
			$logins['nick'] = $rm['userinfo']['nick'];
			$plogin['uid'] = isset($uid)?$uid:$_SESSION['mid'];
			$plogin['openid'] = $rm['openid'];
			if(!$this->where($plogin)->find()) {
				if($this->add($logins)) {
					return true;
				}
			}
		}
	}
	
	/**
	 * 获取登录绑定信息
	 */
	public function loginBindInfos() {
		if(session('?rmm')) {
			$rm = session('rmm');
			$logins['uid'] = $_SESSION['mid'];
			$logins['openid'] = $rm['openid'];
			$logins['type'] = $rm['type'];
			$logins['nick'] = $rm['userinfo']['nick'];
	
			$plogin['uid'] = $_SESSION['mid'];
			$plogin['openid'] = $rm['openid'];
			if(!$this->where($plogin)->find()) {
				if($this->add($logins)) {
					return true;
				}
			}
		}
	}
	
	/**
	 * 查找openid是否存在
	 * @param string $openid
	 */
	public function getOpenidInfo($openid) {
		$data['openid'] = $openid;
		if($this->where($data)->find()) {
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * 删除绑定信息
	 * @param string $openid
	 */
	public function delBindInfo($openid) {
		$data['openid'] = $openid;
		if($this->where($data)->delete()) {
			return true;
		} else {
			return false;
		}
	}
}

?>